package ui.shougao.com.togglebottonexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;


public class MainActivity extends Activity {

    public Switch mSwitch;
    public TextView mSwitchTitleTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mSwitch = (Switch)findViewById(R.id.switch1);
        mSwitchTitleTextView = (TextView)findViewById(R.id.textView2);
        mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    mSwitchTitleTextView.setText("Switch Enable");
                }else{
                    mSwitchTitleTextView.setText("Switch Disable");
                }
            }
        });
    }

    public void onToggleButtonClick(View view){
        if(((ToggleButton)view).isChecked()){
            Toast.makeText(MainActivity.this,"toggleBUttonClick on", Toast.LENGTH_LONG).show();
        }else{
            Toast.makeText(MainActivity.this,"toggleBUttonClick off", Toast.LENGTH_LONG).show();
        }
    }

    public void onSwitchClick(View view){
        Toast.makeText(MainActivity.this,"switchClick", Toast.LENGTH_LONG).show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
